package net.maku.express.biza.service.collectExpress.impl;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import net.maku.commons.biza.handle.CreateSysNOHandler;
import net.maku.commons.biza.util.BarcodeUtil;
import net.maku.custom.biza.mapper.customers.CustomerInfoDao;
import net.maku.custom.biza.pojo.customs.CustomerInfoEntity;
import net.maku.custom.biza.service.customs.impl.CustomerInfoServiceImpl;
import net.maku.express.biza.consts.CollectState;
import net.maku.express.biza.controller.collectExpress.vo.*;
import net.maku.express.biza.convert.CollectExpressConvert;
import net.maku.express.biza.mapper.collectexpress.CollectExpressMapper;
import net.maku.express.biza.mapper.collectexpress.CollectExpressSmallMapper;
import net.maku.express.biza.mapper.collectexpress.LogisticsMapper;
import net.maku.express.biza.mapper.orderlist.OrderListMapper;
import net.maku.express.biza.pojo.collectexpress.CollectExpressPojo;
import net.maku.express.biza.pojo.collectexpress.CollectExpressSmallPojo;
import net.maku.express.biza.pojo.collectexpress.LogisticsPojo;
import net.maku.express.biza.pojo.orderlist.OrderListPojo;
import net.maku.express.biza.service.collectExpress.CollectExpressService;
import net.maku.express.biza.vo.CollectExpressSingleVO;
import net.maku.express.biza.vo.ExpressRelatedDataVO;
import net.maku.framework.common.exception.ErrorCode;
import net.maku.framework.common.service.impl.BaseServiceImpl;
import net.maku.framework.common.utils.Result;
import net.maku.framework.security.user.SecurityUser;
import net.maku.framework.security.user.UserDetail;
import net.maku.infra.api.service.FileApiService;
import net.maku.system.dao.ExpressWarehouseMapper;
import net.maku.system.dao.SysDictDataDao;
import net.maku.system.entity.SysUserEntity;
import net.maku.system.enums.SuperAdminEnum;
import net.maku.system.query.SysDictTypeDataQuery;
import net.maku.system.query.SysUserInfoQuery;
import net.maku.system.service.impl.SysDictDataServiceImpl;
import net.maku.system.service.impl.SysUserServiceImpl;
import net.maku.system.vo.SysDictTypeDataVO;
import net.maku.system.vo.SysUserInfoVO;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.*;

/**
 * @Description:揽件和包的数据
 * @Date
 */
@Service
public class CollectExpressServiceImpl extends BaseServiceImpl<CollectExpressMapper, CollectExpressPojo>
        implements CollectExpressService {

    @Autowired
    private CollectExpressMapper collectExpressMapper;
    @Autowired
    private CollectExpressSmallMapper collectExpressSmallMapper;
    @Autowired
    private CreateSysNOHandler createSysNOHandler;
    @Autowired
    private OrderListMapper orderListMapper;
    @Autowired
    private LogisticsMapper logisticsMapper;
    @Autowired
    private CustomerInfoDao customerInfoDao;

    @Autowired
    private FileApiService fileApiService;
    @Autowired
    protected SysDictDataServiceImpl sysDictDataService;
    @Autowired
    protected SysUserServiceImpl sysUserService;
    @Autowired
    protected CustomerInfoServiceImpl customerInfoService;


    /**
     * 查询数据
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Result<IPage<CollectExpressPageVO>> select(CollectExpressRequestVo collectExpressVOPage) {
        Page<CollectExpressPojo> page = PageDTO.of(collectExpressVOPage.getPage(), collectExpressVOPage.getPageSize());
//        page = collectExpressMapper.selectData(page, collectExpressVOPage, SecurityUser.getUser().getOrgId());
        LambdaQueryWrapper<CollectExpressPojo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        //只获取当前用户自己的数据，管理员除外
        UserDetail userDetail = SecurityUser.getUser();

        if (SuperAdminEnum.NO.getValue().equals(userDetail.getSuperAdmin())){
            lambdaQueryWrapper.eq(CollectExpressPojo::getOperateId, userDetail.getId());
        }

        if (ObjectUtil.isNotNull(collectExpressVOPage.getBusinessState())) {
            lambdaQueryWrapper.like(CollectExpressPojo::getBusinessState, collectExpressVOPage.getBusinessState());
        }
        if (ObjectUtil.isNotEmpty(collectExpressVOPage.getCollectNo())) {
            lambdaQueryWrapper.like(CollectExpressPojo::getCollectNo, collectExpressVOPage.getCollectNo());
        }
        if (ObjectUtil.isNotEmpty(collectExpressVOPage.getExpressNo())) {
            lambdaQueryWrapper.like(CollectExpressPojo::getExpressNo, collectExpressVOPage.getExpressNo());
        }
        if (ObjectUtil.isNotNull(collectExpressVOPage.getGoodsState())) {
            lambdaQueryWrapper.like(CollectExpressPojo::getGoodsState, collectExpressVOPage.getGoodsState());
        }
        if (ObjectUtil.isNotNull(collectExpressVOPage.getShState())) {
            lambdaQueryWrapper.like(CollectExpressPojo::getShState, collectExpressVOPage.getShState());
        }
        page.addOrder(OrderItem.desc("create_time"));
        Page<CollectExpressPojo> pageData = this.page(page, lambdaQueryWrapper);



        IPage<CollectExpressPageVO> pageVO = pageData.convert(collectExpressPojo -> {

            CollectExpressPageVO collectExpPageRecord = new CollectExpressPageVO();
            BeanUtils.copyProperties(collectExpressPojo, collectExpPageRecord);

            /**
             * 从数据字典中取出对应数据
             */
            //设置始发地
            String originCountryStr = "";
            //数据字典查询对象
            SysDictTypeDataQuery sysDictTypeDataQuery = new SysDictTypeDataQuery();

            sysDictTypeDataQuery.setDictValue(collectExpressPojo.getOriginCountry());
            List<SysDictTypeDataVO> originCountryVOList = sysDictDataDao.selectRelList(sysDictTypeDataQuery);
            if(CollectionUtils.isNotEmpty(originCountryVOList)){
                originCountryStr = originCountryVOList.get(0).getDictLabel();
            }
            collectExpPageRecord.setOriginCountry(originCountryStr);

            //设置目的地
            String destinationCountryStr = "";
            sysDictTypeDataQuery.setDictValue(collectExpressPojo.getDestinationCountry());
            List<SysDictTypeDataVO> destinationCountryVOList = sysDictDataDao.selectRelList(sysDictTypeDataQuery);
            if(CollectionUtils.isNotEmpty(destinationCountryVOList)){
                destinationCountryStr = destinationCountryVOList.get(0).getDictLabel();
            }
            collectExpPageRecord.setDestinationCountry(destinationCountryStr);

            //业务类型
            String businessStateStr = "";
            sysDictTypeDataQuery.setDictValue(collectExpressPojo.getBusinessState());
            List<SysDictTypeDataVO> businessStateVOList = sysDictDataDao.selectRelList(sysDictTypeDataQuery);
            if(CollectionUtils.isNotEmpty(businessStateVOList)){
                businessStateStr = businessStateVOList.get(0).getDictLabel();
            }
            collectExpPageRecord.setBusinessState(businessStateStr);

            //客户
            CustomerInfoEntity custom = customerInfoService.getById(collectExpressPojo.getCustomId());
            if(Objects.nonNull(custom)){
                collectExpPageRecord.setCustom(custom.getName());
            }

            //客服
            SysUserEntity business = sysUserService.getById(collectExpressPojo.getBusinessId());
            if(Objects.nonNull(business)){
                collectExpPageRecord.setBusiness(business.getRealName());
            }

            //业务员
            SysUserEntity sales = sysUserService.getById(collectExpressPojo.getSalesId());
            if(Objects.nonNull(sales)){
                collectExpPageRecord.setSales(sales.getRealName());
            }


            return collectExpPageRecord;
        });


        if (pageVO == null) {
            return Result.ok(null);
        }
        return Result.ok(pageVO);
    }

    /**
     * 新增数据
     *
     * @param collectExpressVO
     * @return
     */
    @Resource
    private SysDictDataDao sysDictDataDao;

    @Override
    public Result<Integer> addData(CollectExpressSingleVO collectExpressVO) {
        List<CollectExpressSmallPojo> expressSmallList = Convert
                .toList(CollectExpressSmallPojo.class, collectExpressVO.getSmallVOList());
        if (collectExpressVO.getSmallVOList() == null || expressSmallList.isEmpty()) {
            return Result.error("具体货物不能为空");
        }
        if (collectExpressVO.getCollectNum() != expressSmallList.size()) {
            return Result.error("实际件数与填写货物件数不匹配");
        }
        CollectExpressPojo collectExpressPojo = CollectExpressConvert.INSTANCE.convert(collectExpressVO);
        //设置收据单号
        String expressNo = createSysNOHandler.createSysNo(2, null);
        collectExpressPojo.setCollectNo(expressNo);
        collectExpressPojo.setPackState(1);
        UserDetail user = SecurityUser.getUser();
        collectExpressPojo.setOperateId(user.getId());

        //重量计算，前端处理
//        double weight = 0.0;
//        for (CollectExpressSmallPojo collectExpressSmallPojo : list) {
//            weight += collectExpressSmallPojo.getCollectWeight();
//        }
//        if (weight != collectExpressVO.getWeight()) {
//            return Result.error("实际填写重量与货物重量不匹配!");
//        }

        /**
         * 根据货物明细的货物状态，设置收据单的货物状态
         */

        //未收货列表
        ArrayList<CollectExpressSmallPojo> weiShouHuoList = new ArrayList();
        //已收货列表
        ArrayList yiShouHuoList = new ArrayList();

        for(CollectExpressSmallPojo collectExpressSmallPojo : expressSmallList){
            //设置货物编号
            String goodsNo = createSysNOHandler.createSysNo(1, expressNo);
            collectExpressSmallPojo.setCollectNo(goodsNo);

            if(0 == collectExpressSmallPojo.getCollectState()){
                weiShouHuoList.add(collectExpressSmallPojo);
            }
            if(1 == collectExpressSmallPojo.getCollectState()){
                yiShouHuoList.add(collectExpressSmallPojo);
            }
        }


        if(weiShouHuoList.size() == expressSmallList.size()){
            //未收货
            collectExpressPojo.setArrivedState(0);
        }else if(yiShouHuoList.size() == expressSmallList.size()){
            //已收货
            collectExpressPojo.setArrivedState(1);
        }else{
            //部分收货
            collectExpressPojo.setArrivedState(2);
        }

        //设置打包状态
        collectExpressPojo.setPackState(1);


        String collectNo = createSysNOHandler.createSysNo(2, null);
        collectExpressPojo.setCollectNo(collectNo);
        byte[] dataByte = BarcodeUtil.generateBarEAN13(collectNo, null, null, null, true, 3.0);
        String url = fileApiService.getBarUrl(collectNo + ".png", null, dataByte, "bar", false);
        collectExpressPojo.setBarAnnex(url);
        /**
         * 不知为何原因要做转换，变掉了数值，导致前端取到的值不匹配数据字典对应数据的ID   2024.06.19
         */
//        collectExpressPojo.setGoodsHourseDest(Integer.valueOf(sysDictDataDao.selectById(collectExpressPojo.getGoodsHourseDest()).getDictValue()));
//        collectExpressPojo.setGoodsHourseOrigin(Integer.valueOf(sysDictDataDao.selectById(collectExpressPojo.getGoodsHourseOrigin()).getDictValue()));

        //新增数据
//        int num = collectExpressMapper.insertSelective(collectExpressPojo);
        int num = baseMapper.insert(collectExpressPojo);
        if (num > 0) {
            if (CollectionUtils.isNotEmpty(expressSmallList)) {
                collectExpressSmallMapper.insertBatch(expressSmallList, collectExpressPojo.getId());
            }
            return Result.ok();
        }
        return Result.error("数据写入失败");
    }

    /**
     * 删除数据
     *
     * @param id
     * @return
     */
    @Override
    public Result<String> deleteData(Long id) {
        if (id == null) {
            return Result.error("该数据已删除");
        }
        CollectExpressPojo collectExpressPojo = collectExpressMapper.selectById(id);
        if (collectExpressPojo == null) {
            collectExpressSmallMapper.deleteByCollectExpressId(id);
            return Result.error("该数据已删除");
        }
        List<CollectExpressSmallPojo> list = collectExpressSmallMapper.selectByCollectExpressId(id);
        for (CollectExpressSmallPojo c : list) {
            if (c.getCollectState() != CollectState.COLLECT.getCode()) {
                return Result.error("该数据不能删除," + c.getCollectNo() + CollectState.getValues(c.getCollectState()));
            }
        }
        int num = collectExpressMapper.deleteById(id);
        collectExpressSmallMapper.deleteByCollectExpressId(id);
        return Result.ok("删除成功");
    }

    /**
     * 更新数据
     *
     * @param collectExpressVO
     * @return
     */
    @Override
    public Result<Integer> updateData(CollectExpressSingleVO collectExpressVO) {
        CollectExpressPojo collectExpressPojo = this.getById(collectExpressVO.getId());
        if (collectExpressPojo == null) {
            collectExpressSmallMapper.deleteByCollectExpressId(collectExpressVO.getId());
            return Result.error("该数据已删除!");
        }
        if (collectExpressPojo.getShState() != null && collectExpressPojo.getShState() == 2) {
            return Result.error("该数据已出货，不能修改!");
        }
        if (collectExpressVO.getSmallVOList() == null || collectExpressVO.getSmallVOList().isEmpty()) {
            return Result.error(ErrorCode.NOEMPTY.getCode(), "具体货物不能为空");
        }
        List<CollectExpressSmallPojo> collectExpressSmallPojos = Convert
                .toList(CollectExpressSmallPojo.class, collectExpressVO.getSmallVOList());
        List<CollectExpressSmallPojo> collectExpressSmallPojos1 = collectExpressSmallMapper
                .selectByCollectExpressId(collectExpressVO.getId());

        for (CollectExpressSmallPojo cp1 : collectExpressSmallPojos1) {
            boolean flag = false;
            for (CollectExpressSmallPojo cp : collectExpressSmallPojos) {
                if (Objects.equals(cp1.getId(), cp.getId())) {
                    flag = true;
                    break;
                }
            }
            System.err.println(cp1.getCollectState() + "," + CollectState.COLLECT.getCode());
            if (!flag && cp1.getCollectState() > CollectState.COLLECT.getCode()) {
                return Result.error("该" + cp1.getCollectNo() + "不能修改!");
            }
        }
        CollectExpressPojo collectExpressPojoData = CollectExpressConvert.INSTANCE.convert(collectExpressVO);
        //更新入库信息
        boolean sqlResult = updateById(collectExpressPojoData);
//        int num = collectExpressMapper.updateSelective(collectExpressVO);
        if (true == sqlResult) {
            collectExpressSmallMapper.deleteByCollectExpressId(collectExpressVO.getId());
            collectExpressSmallMapper.insertBatch(collectExpressSmallPojos, collectExpressVO.getId());
        }
        return Result.ok();
    }

    /**
     * 返回编号
     *
     * @return
     */
    @Override
    public Result<String> getSmallSysNo(String receiptId) {
        String sysNo = createSysNOHandler.createSysNo(1, receiptId);
        return Result.ok(sysNo);
    }

    /**
     * 返回编号
     *
     * @return
     */
    @Override
    public Result<String> getSysNo() {
        String sysNo = createSysNOHandler.createSysNo(2, null);
        return Result.ok(sysNo);
    }

    @Override
    public Result<String> getSmallPSysNo() {
        String sysNo = createSysNOHandler.createSysNo(5, null);
        return Result.ok(sysNo);
    }

    /**
     * 小包裹分页
     *
     * @param id
     * @return
     */
    @Override
    public Result<List<GoodsDetailVO>> selectSmall(
            Long id) {
        List<GoodsDetailVO> collectExpressSmallPojos1 = collectExpressSmallMapper
                .selectByCollectExpressId1(id);
        return Result.ok(collectExpressSmallPojos1);
    }


    @Override
    public Result<CollectExpressSingleVO> selectOne(Long id) {
        CollectExpressPojo collectExpressPojo = this.getById(id);
        CollectExpressSingleVO vo = CollectExpressConvert.INSTANCE.convert(collectExpressPojo);

//        CollectExpressSelectiveVO collectExpressSelectiveVO = collectExpressMapper.selective(id);
        if (vo == null) {
            return Result.error("该数据不存在!");
        }
        return Result.ok(vo);
    }

    @Override
    public Result<List<CollectExpressSelectiveVO>> selectOneList(List<Long> id) {
        List<CollectExpressSelectiveVO> list = collectExpressMapper.selective1(id);
        if (list == null || list.isEmpty()) {
            return Result.error("无数据");
        }
        return Result.ok(list);
    }

    @Resource
    private ExpressWarehouseMapper expressWarehouseMapper;

    @Override
    public Result<IPage<Map>> selectPack(CollectPackRequestVO query) {

        Page<Map> page = PageDTO.of(query.getPage(), query.getPageSize());

        List<Map> list = collectExpressMapper.selectPack(page,query);


        for(Map goodsDetail: list){
            SysDictTypeDataQuery sysDictTypeDataQuery = new SysDictTypeDataQuery();
            //设置始发地
            String originCountryStr = "";
            String originCountry = (String) goodsDetail.get("origin_country");
            if(StringUtils.isNotEmpty(originCountry)){
                sysDictTypeDataQuery.setDictValue(originCountry);
                List<SysDictTypeDataVO> originCountryVOList = sysDictDataDao.selectRelList(sysDictTypeDataQuery);
                if(CollectionUtils.isNotEmpty(originCountryVOList)){
                    originCountryStr = originCountryVOList.get(0).getDictLabel();
                }
            }
            goodsDetail.put("origin_country",originCountryStr);

            //设置目的地
            String destinationCountryStr = "";
            String destinationCountry = (String) goodsDetail.get("destination_country");
            if(StringUtils.isNotEmpty(destinationCountry)){
                sysDictTypeDataQuery.setDictValue(destinationCountry);
                List<SysDictTypeDataVO> destinationCountryVOList = sysDictDataDao.selectRelList(sysDictTypeDataQuery);
                if(CollectionUtils.isNotEmpty(destinationCountryVOList)){
                    destinationCountryStr = destinationCountryVOList.get(0).getDictLabel();
                }
            }
            goodsDetail.put("destination_country",destinationCountryStr);

            //业务类型
            String businessStateStr = "";
            String businessState = (String) goodsDetail.get("business_state");
            if(StringUtils.isNotEmpty(businessState)){
                sysDictTypeDataQuery.setDictValue(businessState);
                List<SysDictTypeDataVO> businessStateVOList = sysDictDataDao.selectRelList(sysDictTypeDataQuery);
                if(CollectionUtils.isNotEmpty(businessStateVOList)){
                    businessStateStr = businessStateVOList.get(0).getDictLabel();
                }
            }
            goodsDetail.put("business_state",businessStateStr);

        }
        page.setRecords(list);

        return Result.ok(page);
    }

    @Override
    public Result<List<CollectPackResponseVO>> selectPack1(Long id) {
        List<CollectPackResponseVO> list = collectExpressMapper.selectPack1(id);
        return Result.ok(list);
    }

    @Override
    public Result<List<CollectExpressVO>> selectOrder(CollectExpressOrderRequestVO collectExpressOrderRequestVO) {
        List<CollectExpressPojo> list = collectExpressMapper.selectOrder(collectExpressOrderRequestVO);
        List<CollectExpressVO> list1 = Convert.toList(CollectExpressVO.class, list);
        return Result.ok(list1);
    }

    @Override
    public Result<List<CollectExpressOrderVO>> selectOrder1(Long id) {
        OrderListPojo orderListPojo = orderListMapper.selectById(id);
        String orderNo = orderListPojo.getOrderNo();

        return null;
    }


    @Override
    public Result<List<LogisticsResponseVO>> selectLogistics(Long id) {
        List<LogisticsResponseVO> list = logisticsMapper.selectByCollectExpressId(id);
        return Result.ok(list);
    }

    @Override
    public Result<Integer> addLogistics(LogisticsAddRequestVO addRequestVO) {
        LogisticsPojo logisticsPojo = Convert.convert(LogisticsPojo.class, addRequestVO);
        int num = logisticsMapper.insertSelective(logisticsPojo);
        if (num > 0) {
            return Result.ok();
        }
        return Result.error("添加数据失败");
    }

    @Override
    public Result<Integer> deleteLogistics(Long id) {
        int num = logisticsMapper.deleteById(id);
        if (num > 0) {
            return Result.ok();
        }
        return Result.error("删除失败");

    }

    /**
     * 从数据字典获取相关信息
     * @return
     */
    @Override
    public Result<ExpressRelatedDataVO> getExpressRelatedData(){
        ExpressRelatedDataVO expressRelatedDataVO = new ExpressRelatedDataVO();
        /**
         * 获取国家列表
         */

        SysDictTypeDataQuery query = new SysDictTypeDataQuery();
        query.setDictType("country");
        List<SysDictTypeDataVO> countryDictList = sysDictDataService.queryDictData(query);
        List countryList = new ArrayList<>();
        if(CollectionUtils.isNotEmpty(countryDictList)){
            for(SysDictTypeDataVO sysDictTypeData : countryDictList){
                Map<String,Object> country = new HashMap<>();
                country.put("label",sysDictTypeData.getDictLabel());
                country.put("value",sysDictTypeData.getDictValue());
                countryList.add(country);
            }
        }
        expressRelatedDataVO.setCountryList(countryList);

        /**
         * 获取业务类型列表
         */
        query.setDictType("businessOptions");
        List<SysDictTypeDataVO> businessOptionsDictList = sysDictDataService.queryDictData(query);
        List businessOptionsList = new ArrayList<>();
        if(CollectionUtils.isNotEmpty(businessOptionsDictList)){
            for(SysDictTypeDataVO sysDictTypeData : businessOptionsDictList){
                Map<String,Object> businessOptions = new HashMap<>();
                businessOptions.put("label",sysDictTypeData.getDictLabel());
                businessOptions.put("value",sysDictTypeData.getDictValue());
                businessOptionsList.add(businessOptions);
            }
        }
        expressRelatedDataVO.setBusinessTypeList(businessOptionsList);

        /**
         * 获取客户列表
         */

        List<CustomerInfoEntity> customerList = customerInfoDao.selectList(null);
        if(CollectionUtils.isNotEmpty(customerList)){
            expressRelatedDataVO.setCustomerList(customerList);
        }

        /**
         * 获取用户列表
         */
        SysUserInfoQuery userInfoQuery = new SysUserInfoQuery();
        List<SysUserInfoVO> userInfoList = sysUserService.getUserInfoList(userInfoQuery);
        if(CollectionUtils.isNotEmpty(userInfoList)){
            expressRelatedDataVO.setUserInfoList(customerList);
        }

        //获取送货方式
        query.setDictType("arrivalOptions");
        List<SysDictTypeDataVO> arrivalOptionsDictList = sysDictDataService.queryDictData(query);
        List arrivalOptionsList = new ArrayList<>();
        if(CollectionUtils.isNotEmpty(arrivalOptionsDictList)){
            for(SysDictTypeDataVO sysDictTypeData : arrivalOptionsDictList){
                Map<String,Object> arrivalOptions = new HashMap<>();
                arrivalOptions.put("label",sysDictTypeData.getDictLabel());
                arrivalOptions.put("value",sysDictTypeData.getDictValue());
                arrivalOptionsList.add(arrivalOptions);
            }
        }
        expressRelatedDataVO.setArrivalOptionsList(arrivalOptionsList);

        //获取送货方式
        query.setDictType("payment");
        List<SysDictTypeDataVO> paymentDictList = sysDictDataService.queryDictData(query);
        List paymentList = new ArrayList<>();
        if(CollectionUtils.isNotEmpty(paymentDictList)){
            for(SysDictTypeDataVO sysDictTypeData : paymentDictList){
                Map<String,Object> payment = new HashMap<>();
                payment.put("label",sysDictTypeData.getDictLabel());
                payment.put("value",sysDictTypeData.getDictValue());
                paymentList.add(payment);
            }
        }
        expressRelatedDataVO.setPaymentList(paymentList);

        //计费重类型
        query.setDictType("chargedOptions");
        List<SysDictTypeDataVO> chargedOptionsDictList = sysDictDataService.queryDictData(query);
        List chargedOptionsList = new ArrayList<>();
        if(CollectionUtils.isNotEmpty(chargedOptionsDictList)){
            for(SysDictTypeDataVO sysDictTypeData : chargedOptionsDictList){
                Map<String,Object> chargedOptions = new HashMap<>();
                chargedOptions.put("label",sysDictTypeData.getDictLabel());
                chargedOptions.put("value",Integer.parseInt(sysDictTypeData.getDictValue()));
                chargedOptionsList.add(chargedOptions);
            }
        }
        expressRelatedDataVO.setChargedOptionsList(chargedOptionsList);

        //货物类型
        query.setDictType("collectTypeOptions");
        List<SysDictTypeDataVO> collectTypeOptionsDictList = sysDictDataService.queryDictData(query);
        List collectTypeOptionsList = new ArrayList<>();
        if(CollectionUtils.isNotEmpty(collectTypeOptionsDictList)){
            for(SysDictTypeDataVO sysDictTypeData : collectTypeOptionsDictList){
                Map<String,Object> collectTypeOptions = new HashMap<>();
                collectTypeOptions.put("label",sysDictTypeData.getDictLabel());
                collectTypeOptions.put("value",Integer.parseInt(sysDictTypeData.getDictValue()));
                collectTypeOptionsList.add(collectTypeOptions);
            }
        }
        expressRelatedDataVO.setCollectTypeOptionsList(collectTypeOptionsList);

        //货物状态
        query.setDictType("cargoOptions");
        List<SysDictTypeDataVO> cargoOptionsDictList = sysDictDataService.queryDictData(query);
        List cargoOptionsList = new ArrayList<>();
        if(CollectionUtils.isNotEmpty(cargoOptionsDictList)){
            for(SysDictTypeDataVO sysDictTypeData : cargoOptionsDictList){
                Map<String,Object> cargoOptions = new HashMap<>();
                cargoOptions.put("label",sysDictTypeData.getDictLabel());
                cargoOptions.put("value",Integer.parseInt(sysDictTypeData.getDictValue()));
                cargoOptionsList.add(cargoOptions);
            }
        }
        expressRelatedDataVO.setCargoOptionsList(cargoOptionsList);


        return Result.ok(expressRelatedDataVO);
    }
}
